<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\wxapp\controller;

use cmf\controller\RestBaseController;
use think\facade\Request;
use api\wxapp\model\Config;
use think\Db;
class ApiBaseController extends RestBaseController
{
    // public function __construct()
    // {
    //     parent::__construct();
    //     header("Access-Control-Allow-Origin: *");
    //     header("Access-Control-Allow-Methods: *");
    //     header('Access-Control-Allow-Headers:x-requested-with,content-type');
    //     $key = Request::controller().'_'.Request::action();
    //     //$this->success('请求成功',$key);
    //     if(array_key_exists($key,Config::MODEL_TYPE)){
    //         $method = Request::method();
    //         $params = Request::param();
    //         $this->$method($params,Config::MODEL_TYPE[$key]);
    //     }
    //     //$this->success('请求成功',Config::MODEL_TYPE);
    // }
    //获取访问方式
    protected function getMethod()
    {
        $method = Request::method();
        return $method;
    }
    //获取访问控制器
    protected function getContro()
    {
        $controller = Request::controller();
        return $controller;
    }
    //获取访问方法
    protected function getAction()
    {
        $action = Request::action();
        return $action;
    }
    //获取访问参数
    protected function getParam()
    {
        $param = Request::param();
        return $param;
    }
 
     ///验证  uid
     public function checkuid($params)
     {
        if(!isset($params['uid'])){
            $this->error('缺少参数uid!!!',false);
        }
     }
     ///验证  goods_id
     public function checkgoodsId($params)
     {
        if(!isset($params['goods_id'])){
            $this->error('缺少参数goods_id!!!',false);
        }
     }
     ///验证  content
     public function checkcontent($params)
     {
        if(!isset($params['content'])){
            $this->error('缺少参数content!!!',false);
        }
     }
     ///验证  shop_id
     public function checkshopid($params)
     {
        if(!isset($params['shop_id'])){
            $this->error('缺少参数shop_id!!!',false);
        }
     }
     //验证 img
     public function checkimg($params)
     {
        if(!isset($params['img'])){
            $this->error('缺少参数img!!!',false);
        }
     }
     //验证 img
     public function checkid($params)
     {
        if(!isset($params['id'])){
            $this->error('缺少参数id!!!',false);
        }
     }
     //返回当前时间
     public function returnDate()
     {
         return date('Y-m-d',time());
     }
     //返回当前时间
     public function returnDateTime()
     {
         return date('Y-m-d H:i:s',time());
     }
     //生成不重复订单号
     public function getOrderNum($uid)
     {
         return chr(rand(65,90)).$uid.time();
     }
}
